package wiki.kaizen.cloud.plugin.redis;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import wiki.kaizen.cloud.plugin.redis.serializer.FastJson2JsonRedisSerializer;
import wiki.kaizen.cloud.plugin.redis.service.RedisTemplateService;

@Import(
    RedisTemplateService.class
)
public class KaizenPluginRedisAutoconfigure {

    @Bean(name = "kaizenRedisTemplate")
    public RedisTemplate<String, Object> kaizenRedisTemplate(RedisConnectionFactory connectionFactory) {
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        template.setConnectionFactory(connectionFactory);
        template.setValueSerializer(new FastJson2JsonRedisSerializer<>(Object.class));
        template.setKeySerializer(new StringRedisSerializer());
        template.afterPropertiesSet();
        return template;
    }
}
